﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace M3G {
    public abstract class AppearanceBase : Object3D {

        #region Field
        int             layer;
        PolygonMode     polygonMode;
        CompositingMode compositingMode;
        bool            depthSortEnabled;
        #endregion

        #region Method
        public AppearanceBase () {
            layer = 0;
            polygonMode = null;
            compositingMode = null;
            depthSortEnabled = false;
        }

        protected AppearanceBase (AppearanceBase appearance)
            : base (appearance) {
            this.layer = appearance.layer;
            this.polygonMode = appearance.polygonMode;
            this.compositingMode = appearance.compositingMode;
            this.depthSortEnabled = appearance.depthSortEnabled;
        }


        public CompositingMode CompositingMode {
            get { return compositingMode; }
        }

        public void SetCompositingMode (CompositingMode compositingMode) {
            this.compositingMode = compositingMode;
        }

        public int Layer {
            get { return layer; }
            set {
                var layer = value;
                if (layer < -63 || layer > 63) {
                    throw new ArgumentOutOfRangeException ("Layer index must be within [-63,63], layer=" + layer);
                }
                this.layer = layer;
            }
        }

        public PolygonMode PolygonMode {
            get { return polygonMode; }
        }

        public void SetPolygonMode (PolygonMode polygonMode) {
            this.polygonMode = polygonMode;
        }

        public bool DepthSortEnabled {
            get { return depthSortEnabled; }
            set { depthSortEnabled = value; }
        }

        public override Object3D[] References {
            get {
                var q = new List<Object3D> ();
                q.AddRange (base.References);
                q.Add (compositingMode);
                q.Add (polygonMode);
                q.RemoveAll (x => x == null);
                return q.ToArray ();
            }
        }


        #endregion
    }
}
